<!DOCTYPE html>
<html class="x-admin-sm">
  <head>
    <meta charset="UTF-8">
    <title>role</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8" />
    <link rel="stylesheet" href="{*cdn*}css/font.css">
    <link rel="stylesheet" href="{*cdn*}css/xadmin.css">
    <link rel="stylesheet" href="{*cdn*}lib/layui/css/layui.css" media="all">
    <script src="{*cdn*}lib/layui/layui.js"></script>
    <script src="{*cdn*}js/xadmin.js"></script>
    <!--[if lt IE 9]>
      <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
      <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
  </head>
  <body class="index">
    <table class="layui-table" lay-data="{id:'table', headers:{token:'{*token*}'}, url:'{*api_url*}?token={*token*}&action=list', height:'full', toolbar: '#headertoolbar', page: true}" lay-filter="table">
      <thead>
        <tr>
          <th lay-data="{align:'center', type:'numbers'}">#</th>
          <th lay-data="{field:'name', align:'center', width: 100}">{* locale['dashboard.menu.role_manage.table.name'] *}</th>
          <th lay-data="{field:'create_at', align:'center', }">{* locale['dashboard.menu.role_manage.table.create_time'] *}</th>
          <th lay-data="{field:'update_at', align:'center', }">{* locale['dashboard.menu.role_manage.table.update_time'] *}</th>
          <th lay-data="{fixed:'right', align:'center', toolbar: '#optionsToolBar'}">{* locale['dashboard.menu.role_manage.table.options'] *}</th>
        </tr>
      </thead>
    </table>
    <script type="text/html" id="optionsToolBar">
      <div class="layui-btn-container">
        <a class="layui-btn layui-btn-xs layui-btn-normal" lay-event="edit">{* locale['dashboard.menu.role_manage.table.options.edit'] *}</a>
        <a class="layui-btn layui-btn-xs layui-btn-danger" lay-event="delete">{* locale['dashboard.menu.role_manage.table.options.delete'] *}</a>
      </div>
    </script>
    <script type="text/html" id="headertoolbar">
      <div class="layui-btn-container">
        <!-- 刷新按钮  -->
        <button class="layui-btn layui-btn-xs" onclick='window.location.reload()'><i class="iconfont">&#59050;</i> {*locale['dashboard.menu.role_manage.table.reflush']*}</button>
        <!-- 新增用户按钮  -->
        <button class="layui-btn layui-btn-xs" onclick='xadmin.open("{* locale['dashboard.menu.user_manage.table.adduser'] *}", "{*role_add_url*}", 550, 430)'><i class="iconfont">&#59065;</i> {*locale['dashboard.menu.role_manage.table.options.add']*}</button>
        <!-- <button class="layui-btn layui-btn-xs" onclick='newuser()'><i class="iconfont">&#59065;</i> {* locale['dashboard.menu.role_manage.table.adduser'] *}</button> -->
      </div>
    </script>
    <script type="text/javascript">
      var {form, table} = {};
      layui.use('table', function(){
        $ = layui.jquery;
        table = layui.table;
        form = layui.form;
        //监听工具条
        table.on('tool(table)', function(obj){
          var data = obj.data;
          if(obj.event === 'delete'){
            layer.confirm("", {
              title:"{*locale['dashboard.menu.role_manage.table.options.delete']*}",
              content:"{*locale['dashboard.menu.role_manage.table.options.confirm']*}",
            }, function(index){
              $.ajax({
                url: "{*api_url*}", type: "POST", headers: {token:"{*token*}"}, data: { action: "delete", id: data.id, token: "{*token*}"},
                error: function (res) {
                  return layer.msg('请求失败', {time:2000});
                },
                success: function (res) {
                  if (res.code != 0) {
                    return layer.msg(res.msg, {time:2000});
                  }
                  return layer.msg(res.msg, {time:1000}, function () {
                    return window.location.reload();
                  });
                },
              })
              return false;
            });
          } else if(obj.event === 'edit'){
            return xadmin.open("{*locale['dashboard.menu.role_manage.table.options.edit']*}", "{*role_edit_url*}?id=" + data.id, 550, 430);
          };
        });

      });
      </script>
  </body>
</html>
